package com.hk.Mgr.web.controller.app;

import com.hk.api.ProcessAPI;
import com.hk.base.BaseCtrl;
import com.hk.commons.PrivateProductConstant;
import com.hk.commons.ResultCode;
import com.hk.commons.entity.Parameter;
import com.hk.commons.vo.JsonResult;
import com.hk.service.kyc.IAgreement;
import com.hk.service.order.IParameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 *私募产品
 * @author Evan
 * @date 2017/10/31
 */
@Controller
@RequestMapping(value = BaseCtrl.App + "/privateProductCtrl")
public class PrivateProductCtrl {


    @Autowired
    private IParameter parameterService;

    @Autowired
    private IAgreement agreementService;



    /**
     * 获取私募协议
     * @param request
     * @return
     */
    @RequestMapping(value = "/getPrivateProductAgreement", method = RequestMethod.GET)
    @ResponseBody
    public JsonResult getPrivateProductAgreement(HttpServletRequest request,Long userId){
        ProcessAPI api = (jsonResult, validate) -> {
            Parameter parameter = parameterService.getByName(PrivateProductConstant.PRIVATE_PRODUCT_AGREEMENT_Key);
            if(parameter == null || parameter.getValue01() == null){
                jsonResult.resultCode = ResultCode.FAILED.getCode();
                jsonResult.msg = ResultCode.FAILED.getMsg();
            }

            String agreementInfo = agreementService.getByInfo(Long.valueOf(parameter.getValue01()),userId,null);
            jsonResult.result = agreementInfo;
        };
        return api.process(request);
    }





}
